using Godot;
using System;
using System.Collections.Generic;

public static class RegisteryItemHelp
{
    public static List<ItemMateria> RegisteryComponents(String id, String DisPlayName)
    {
        List<ItemMateria> ims = new List<ItemMateria>();
        ims.Add(
        Materials.RegistryItem(
        new ItemMateria($"{id}_plate")
        .SetDisplayName($"{DisPlayName}板")
        .SetMaxAmount(64)
        ));
        ims.Add(
        Materials.RegistryItem(
        new ItemMateria($"{id}_stick")
        .SetDisplayName($"{DisPlayName}棍")
        .SetMaxAmount(64)
        ));
        return ims;
    }
    public static List<ItemMateria> RegisteryTool(String id, String DisPlayName, int level, int druabel,
        bool pickaxe = true,
        bool axe = true,
        bool shovel = true,
        bool hammer = true,
        bool hoe = true,
        bool wrench = true
        )
    {
        List<ItemMateria> ims = new List<ItemMateria>();
        if (pickaxe) ims.Add(
            Materials.RegistryItem(
                new ItemMateria($"{id}_pickaxe")
                .SetDisplayName($"{DisPlayName}镐")
                .SetMaxAmount(1)
                .SetItemData(() => new ToolData(new Tool(ToolType.PickAxe, level), druabel))
        ));
        if (axe) ims.Add(
            Materials.RegistryItem(
                new ItemMateria($"{id}_axe")
                .SetDisplayName($"{DisPlayName}斧")
                .SetMaxAmount(1)
                .SetItemData(() => new ToolData(new Tool(ToolType.Axe, level), druabel))
        ));
        if (shovel) ims.Add(
            Materials.RegistryItem(
                new ItemMateria($"{id}_shovel")
                .SetDisplayName($"{DisPlayName}铲")
                .SetMaxAmount(1)
                .SetItemData(() => new ToolData(new Tool(ToolType.Shovel, level), druabel))
        ));
        if (hammer) ims.Add(
            Materials.RegistryItem(
                new ItemMateria($"{id}_hammer")
                .SetDisplayName($"{DisPlayName}锤")
                .SetMaxAmount(1)
                .SetItemData(() => new ToolData(new Tool(ToolType.Hammer, level), druabel))
        ));
        if (hoe) ims.Add(
            Materials.RegistryItem(
                new ItemMateria($"{id}_hoe")
                .SetDisplayName($"{DisPlayName}锄")
                .SetMaxAmount(1)
                .SetItemData(() => new ToolData(new Tool(ToolType.Hammer, level), druabel))
                .SetPlayerUseItem((PlayerUseItemEvent e) =>
                {
                    if (e.block != null)
                    {
                        if (e.block.Name == "grass" || e.block.Name == "dirt")
                        {
                            e.block.SetBlock(Materials.Farmland);
                            if (!(e.item.itemData as ToolData).SubDurable(1)) e.player.store.SubAmount(1);
                        }
                    }
                    return true;
                })
        ));
        if (wrench) ims.Add(
        Materials.RegistryItem(
            new ItemMateria($"{id}_wrench")
            .SetDisplayName($"{DisPlayName}扳手")
            .SetMaxAmount(1)
            .SetItemData(() => new ToolData(new Tool(ToolType.Wrench, level), druabel))
            .SetPlayerUseItem((PlayerUseItemEvent e) =>
            {
                if (e.block != null && e.block.blockEntity != null)
                {
                    GD.Print(e.block.blockEntity.toJson());
                }
                return true;
            })
        ));
        return ims;
    }
}